# encoding: utf-8

module Wiki
    # 进入某个wiki的修改、删除、添加页面
    def wiki_operate_page(user, project, wiki_title)
        go_in_wiki_page(user, project)

        @driver.find_element(:link, "页面").click
        @driver.find_element(:link, "#{wiki_title}").click
    end

    # 添加wiki
    def add_wiki(user, project, wiki_title, wiki_desc)
        go_in_wiki_page(user, project)

        # 进入wiki添加页面
        @driver.find_element(:link, "新页面").click

        # 添加wiki内容
        @driver.find_element(:id, "gollum-editor-page-title").clear
        @driver.find_element(:id, "gollum-editor-page-title").send_keys wiki_title
        @driver.find_element(:id, "gollum-editor-body").clear
        @driver.find_element(:id, "gollum-editor-body").send_keys wiki_desc
        @driver.find_element(:id, "gollum-editor-submit").click
    end

    # 删除某个wiki页面
    def delete_wiki(user, project, wiki_title)
        wiki_operate_page(user, project, wiki_title)

        @driver.find_element(:link, "删除").click
        @driver.find_element(:id, "remove-wiki-dialog").find_element(:tag_name, "a").click
    end

    # 更新wiki内容
    def update_wiki(user, project, wiki_title)
        wiki_operate_page(user, project, wiki_title)

        @driver.find_element(:link, "编辑").click
        @driver.find_element(:id, "gollum-editor-body").send_keys $basic_config['project']['wiki_update_desc']
        @driver.find_element(:id, "gollum-editor-submit").click
    end
end